package com.veryGood.service.Impl;

import com.veryGood.common.constant.Constants;
import com.veryGood.common.result.LayuiResultJson;
import com.veryGood.common.result.R;
import com.veryGood.domain.pojo.DrugInfo;
import com.veryGood.domain.pojo.SalesInfo;
import com.veryGood.mapper.DrugMngMapper;
import com.veryGood.mapper.SaleMapper;
import com.veryGood.service.DrugMngService;
import com.veryGood.service.SaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 药品管理
 */
@Service
public class SaleServiceImpl implements SaleService {

    @Autowired
    private SaleMapper saleMapper;

    //添加药品
    @Override
    public R addSale(SalesInfo salesInfo) {
        System.out.println(salesInfo);
        return R.success(saleMapper.addSale(salesInfo));
    }

    //分页查询药品信息
    @Override
    public LayuiResultJson findSaleAll(Integer page, Integer limit) {
        LayuiResultJson layuiResultJson = new LayuiResultJson();
        //设置分页
        Integer offset = (page - 1)*limit;
        Integer rows = limit;
        //调用mapper
        List<SalesInfo> saleList = saleMapper.findSaleList(offset,rows);
        layuiResultJson.setCode(Constants.OK);
        layuiResultJson.setMsg(Constants.MESSAGE_OK);
        Integer totalSize = saleMapper.countSale();
        layuiResultJson.setCount(totalSize);
        layuiResultJson.setData(saleList);
        return layuiResultJson;
    }

    //删除药品
    @Override
    public R delSaleById(Integer id) {
        int result = saleMapper.delSaleById(id);
        if(result > 0 ){
            return R.success("删除成功！");
        }
        return R.error();
    }
}
